/*
*VMukti -- An open source video conferencing platform.
*
* Copyright (C) 2007 - 2008, VMukti Solutions Pvt. Ltd.
*
* Hardik Sanghvi <hardik@vmukti.com>
*
* See http://www.vmukti.com for more information about
* the VMukti project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, forums and mailing lists
* for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
using VMukti.DataAccess;
using System.Data.SqlClient;
using System.Collections.Generic;
using VMukti.Business.CommonDataContracts;
using VMuktiAPI;


namespace VMukti.Business
{
    public class ClsPageCollection : ClsBaseCollection<ClsPageLogic>
    {
        public static ClsPageCollection GetAll()
        {
            ClsPageCollection obj = new ClsPageCollection();
            if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.NodeWithHttp)
            {


                //ExecuteDataSet("select pagetitle,id from page where isdeleted='false'", CommandType.Text, null);

                //shilpa code
                //11-Feb-2008
                try
                {
                obj.MapObjects(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("select pagetitle,id from page where isdeleted='false'").dsInfo);
                }
                catch (System.ServiceModel.EndpointNotFoundException e)
                {
                    e.Data.Add("My Key", "GetAll()--:--ClsPageCollection.cs--:--" + e.Message + " :--:--");
                    ClsException.LogError(e);
                    ClsException.WriteToErrorLogFile(e);
                    VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                    obj.MapObjects(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("select pagetitle,id from page where isdeleted='false'").dsInfo);
                }
                catch (System.ServiceModel.CommunicationException e)
                {
                    e.Data.Add("My Key", "GetAll()--:--ClsPageCollection.cs--:--" + e.Message + " :--:--");
                    ClsException.LogError(e);
                    ClsException.WriteToErrorLogFile(e);
                    VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                    obj.MapObjects(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("select pagetitle,id from page where isdeleted='false'").dsInfo);
                }
                //end shilpa code
                //11-Feb-2008


            }
            else
            {
                obj.MapObjects(new ClsPageDataService().GetPages());
            }
            return obj;
        }

        public static ClsPageCollection GetUPageAllocated(int intUserId)
        {
            ClsPageCollection obj = new ClsPageCollection();
            if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.NodeWithHttp)
            {
                //ExecuteDataSet("spGetUsersPageAllocated", CommandType.StoredProcedure,
               //CreateParameter("@pUserID", SqlDbType.BigInt, intUserId));

                List<clsSqlParametersInfo> lstSP = new List<clsSqlParametersInfo>();

                clsSqlParametersInfo objInfo = new clsSqlParametersInfo();
                objInfo.Direction = "Input";
                objInfo.PName = "@pUserID";
                objInfo.PValue = intUserId;
                objInfo.PDBType = "BigInt";
                objInfo.PSize = 200;

                lstSP.Add(objInfo);
                
                clsSqlParameterContract CSqlInfo = new clsSqlParameterContract();
                CSqlInfo.objParam = lstSP;

                //shilpa code
                //11-Feb-2008
                try
                {
                obj.MapObjects(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("spGetUsersPageAllocated", CSqlInfo).dsInfo);
                }
                catch (System.ServiceModel.EndpointNotFoundException e)
                {
                    e.Data.Add("My Key", "GetUPageAllocated(int intUserId)--:--ClsPageCollection.cs--:--" + e.Message + " :--:--");
                    ClsException.LogError(e);
                    ClsException.WriteToErrorLogFile(e);
                    VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                    obj.MapObjects(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("spGetUsersPageAllocated", CSqlInfo).dsInfo);
                }
                catch (System.ServiceModel.CommunicationException e)
                {
                    e.Data.Add("My Key", "GetUPageAllocated(int intUserId)--:--ClsPageCollection.cs--:--" + e.Message + " :--:--");
                    ClsException.LogError(e);
                    ClsException.WriteToErrorLogFile(e);
                    VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                    obj.MapObjects(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("spGetUsersPageAllocated", CSqlInfo).dsInfo);
                }

                //end shilpa code
                //11-Feb-2008
            }
            else
            {
                obj.MapObjects(new ClsPageDataService().GetPageAllocated(intUserId));
            }
            return obj;
        }
    }
}
